home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_basi / agavb25.zip / VC.ZIP / VCDEMVW.CPP < prev    next >
C/C++ Source or Header  |  1996-01-20  |  3KB  |  120 lines

  1. // vcdemvw.cpp : implementation of the CVcdemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include "vcdemo.h"
  7.  
  8. #include "vcdemdoc.h"
  9. #include "vcdemvw.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CVcdemoView
  18.  
  19. IMPLEMENT_DYNCREATE(CVcdemoView, CFormView)
  20.  
  21. BEGIN_MESSAGE_MAP(CVcdemoView, CFormView)
  22.     //{{AFX_MSG_MAP(CVcdemoView)
  23.     ON_WM_CREATE()
  24.     ON_WM_TIMER()
  25.     ON_WM_DESTROY()
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CVcdemoView construction/destruction
  31.  
  32. CVcdemoView::CVcdemoView()
  33.     : CFormView(CVcdemoView::IDD)
  34. {
  35.     //{{AFX_DATA_INIT(CVcdemoView)
  36.     m_speed = NULL;
  37.     m_direction = NULL;
  38.     //}}AFX_DATA_INIT
  39.     // TODO: add construction code here
  40. }
  41.  
  42. CVcdemoView::~CVcdemoView()
  43. {
  44. }
  45.  
  46. void CVcdemoView::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CFormView::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CVcdemoView)
  50.     DDX_VBControl(pDX, IDC_SPEED, m_speed);
  51.     DDX_VBControl(pDX, IDC_DIRECTION, m_direction);
  52.     //}}AFX_DATA_MAP
  53.     
  54.     SetTimer(1,55,NULL);
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CVcdemoView diagnostics
  59.  
  60. #ifdef _DEBUG
  61. void CVcdemoView::AssertValid() const
  62. {
  63.     CFormView::AssertValid();
  64. }
  65.  
  66. void CVcdemoView::Dump(CDumpContext& dc) const
  67. {
  68.     CFormView::Dump(dc);
  69. }
  70.  
  71. CVcdemoDoc* CVcdemoView::GetDocument() // non-debug version is inline
  72. {
  73.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVcdemoDoc)));
  74.     return (CVcdemoDoc*)m_pDocument;
  75. }
  76. #endif //_DEBUG
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CVcdemoView message handlers
  80.  
  81. int CVcdemoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  82. {
  83.     if (CFormView::OnCreate(lpCreateStruct) == -1)
  84.         return -1;
  85.     
  86.     return 0;
  87. }
  88.  
  89. void CVcdemoView::OnTimer(UINT nIDEvent)
  90. {
  91. float speed, direction;
  92.  
  93.     CFormView::OnTimer(nIDEvent);
  94.     
  95.     speed = m_speed->GetFloatProperty("NeedleValue");
  96.     direction = m_direction->GetFloatProperty("NeedleValue");
  97.     
  98.     speed += (float) rand()/ (float) RAND_MAX * (float) 4 - (float) 2;
  99.     direction += (float) rand()/ (float) RAND_MAX * (float) 6 - (float) 3;
  100.     
  101.     if (direction<0) direction += 360;
  102.     if (direction>360) direction -= 360;
  103.     
  104.     m_speed->SetFloatProperty("NeedleValue",speed);
  105.     
  106.     m_direction->SetNumProperty("TicID",0);
  107.     m_direction->SetFloatProperty("TicFloatOffset",-direction);
  108.     m_direction->SetNumProperty("TicID",1);
  109.     m_direction->SetFloatProperty("TicFloatOffset",-direction);
  110.     m_direction->SetFloatProperty("NeedleValue",direction);
  111. }
  112.  
  113. void CVcdemoView::OnDestroy()
  114. {
  115.     CFormView::OnDestroy();
  116.     
  117.     KillTimer(1);
  118.     
  119. }
  120.